package com.king.tv.mvp.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.king.base.util.ToastUtils;
import com.king.tv.Constants;
import com.king.tv.R;
import com.king.tv.mvp.base.BaseFragment;
import com.king.tv.mvp.base.BasePresenter;
import com.king.tv.mvp.base.BaseView;
import com.zhangqie.zqvideolibrary.ZQVideoPlayer;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
 * @since 2017/3/9
 */

public class FollowFragment extends BaseFragment<BaseView, BasePresenter<BaseView>> {

    @BindView(R.id.ivLeft)
    ImageView ivLeft;
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.ivRight)
    ImageView ivRight;

    public static FollowFragment newInstance() {
        Bundle args = new Bundle();
        FollowFragment fragment = new FollowFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getRootViewId() {
        return R.layout.fragment_follow;
    }

    @Override
    public void initUI() {
        tvTitle.setText(R.string.tab_follw);
        ivLeft.setVisibility(View.GONE);
        replaceChildFragment(R.id.fragment,LiveVideoFragment.newInstance("",2));
    }

    @Override
    public void initData() {

    }

    @OnClick({R.id.ivLeft, R.id.ivRight})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ivLeft:
                startActivity(getFragmentIntent(Constants.SEARCH_FRAGMENT));
                break;
            case R.id.ivRight:
                startLogin();
                break;
        }
    }

    @Override
    public BasePresenter<BaseView> createPresenter() {
        return new BasePresenter<BaseView>(getApp());
    }

    @Override
    public void onPause() {
        super.onPause();
        Log.i("tag","==========isplay follow onPause");
//        ZQVideoPlayer.releaseAllVideos();
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser) {
            Log.i("tag","==========isplay 相当于Fragment的onResume1");
            //相当于Fragment的onResume
        } else {
            Log.i("tag","==========isplay  相当于Fragment的onPauseonPause");
            //相当于Fragment的onPause
        }
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if(hidden==true){
            Log.i("tag","==========isplay 相当于Fragment的onResume1 onHiddenChanged true");
            ZQVideoPlayer.releaseAllVideos();
        }else{
            Log.i("tag","==========isplay 相当于Fragment的onResume1 onHiddenChanged false");
        }
    }
}
